/*
 * @Author: MuQuanyu(MQy)
 * @Date: 2025-08-30 11:11:41
 * @LastEditTime: 2025-10-11 15:34:11
 * @email: muquanyu@outlook.com
 */
import { http } from "@/utils/http";
import type { Token } from "@/utils/http/types";
import type { RegisterForm, UserPwdForm } from "@/views/Login/types";
import type { User, UserInfoVO } from "./types";
import type { PageParams } from "@/api/types";

export function GetGraphCode() {
  // skipErrorHandling: true 意思是不进行统一错误处理
  // noRefreshToken: true 意思是不触发刷新Token（部分请求可能需要此选项，正常都是401错误才会触发刷新）
  return http.get<string>(
    "/api/sys-auth-code/graph",
    {},
    { skipErrorHandling: true, noRefreshToken: true }
  );
}

// 账号密码登录
export function LoginUserPwd(userPwdForm: UserPwdForm, params: object) {
  return http.post<Token>("/api/sys-user/login", userPwdForm, {
    skipErrorHandling: true,
    noRefreshToken: true,
    params,
  });
}

// 注册账号密码
export function RegisterUserPwd(registerForm: RegisterForm, params: object) {
  return http.post<Token>("/api/sys-user/add", registerForm, {
    skipErrorHandling: true,
    noRefreshToken: true,
    params,
  });
}
// 获取动态路由树列表
export function GetSysRouteTree() {
  return http.get<Token>("/api/sys-route/tree", {}, {});
}

// 获取个人信息
export function GetUserInfo() {
  return http.get<UserInfoVO>("/api/sys-user/person-info", {}, {});
}

// 获取个人信息
export function GetUserPage(pageParams: PageParams) {
  return http.get<User[]>("/api/sys-user/page", pageParams, {});
}
